﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.scene;
using Imaginecup.componentSystem.component;
using Imaginecup.stage;
using Imaginecup.component.scene;
using Imaginecup.loop;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.gameState.malaria.manager;

namespace Imaginecup.gameState.darkRain.manager
{
    public class SceneMan : ISceneInfo, ISceneMan
    {
        private List<ICmpScene> m_SceneList = new List<ICmpScene>();      
        private BaseStage m_Stage;

        public SceneMan(BaseStage baseStage)
        {
            m_Stage = baseStage;
        }
    

        public void AddScene(ICmpScene minimap)
        {
            m_SceneList.Add(minimap);
        }

        public ICmpScene GetScene(int index)
        {
            return m_SceneList[index];
        }



        public void Release()
        {
            if (m_SceneList == null) return;
            for (int i = m_SceneList.Count - 1; i >= 0; i--)
            {
                ICmpScene cmpScene = m_SceneList[i];
                SceneData sceneData = (SceneData)cmpScene.GetSceneData();
                sceneData.Release();
            }

            m_SceneList.Clear();
            m_SceneList = null;
            m_Stage = null;
        }

       

        public void Update(GameTime gameTime)
        {

            foreach (ICmpScene cmpScene in m_SceneList)
            {
                SceneData sceneData = (SceneData)cmpScene.GetSceneData();
                IUpdateAble updateAble = sceneData.GetUpdateAble();
                updateAble.SetData(cmpScene.IsSelectedScene());
                updateAble.Update(gameTime);
            }

            m_Stage.CheckGameState();
        }

        public void Draw(GameTime gameTime, SpriteBatch sb)
        {
            foreach (ICmpScene cmpScene in m_SceneList)
            {
                if (!cmpScene.IsSelectedScene()) continue; // 선택된것만 그리기 위해
                SceneData sceneData = (SceneData)cmpScene.GetSceneData();
                IDrawAble drawAble = sceneData.GetDrawAble();
                drawAble.Draw(gameTime, sb);
            }

        }
    }
}
